"""
@name : 对战游戏
@author : maxueyan
@projectname: sanchuang
"""

import random
class Role(object):
    def __init__(self,name,sex,blood=100):
        self.name = name
        self.sex = sex
        self.blood = blood
        self.room = None

    def attack(self,other):
        if self == other:
            print("不能攻击自己")
        else:
            if self.room and self.room == other.room:
                if self.blood <= 0:
                    print("血量低于0，无法进行攻击！")
                else:
                    if random.choice([0,1]) == 0:
                        lost_blood = 10
                        print(f"{other.name}没有装备哟！")
                    else:
                        lost_blood = 5
                        print(f"{other.name}使用了装备哟！")
                    other.blood = other.blood - lost_blood
                    if other.blood <= 0:
                        print(f"{other.name}已阵亡，无法进行攻击！")
                        exit()
            else:
                print("请加入同一个房间，否则不能进行攻击")

class Room(object):
    def __init__(self,name):
        self.name = name
        self.member_list = []

    def add_member(self,role):
        if role.room == None:
            if len(self.member_list) < 2:
                self.member_list.append(role)
                role.room = self
                print(f"{role.name}成功加入{self.name}房间")
        else:
            print(f"{role.name}已加入{role.room.name}房间")

print("""
~~~~~~~~welcome~~~~~~~~
1、创建角色
2、创建房间
3、加入房间
4、开始战斗
5、退出游戏
~~~~~~~~good luck~~~~~~~
""")
roles = {}
rooms = {}
while True:
    choose = input("请输入你的选择：")
    if choose.isdigit():
        choose = int(choose)
        if 1 <= choose <= 5:
            if choose == 1:
                name,sex = input("请输入角色昵称与性别(请用空格隔开)：").split()
                roles[name] = Role(name,sex)
            elif choose == 2:
                room = input("请输入房间昵称：")
                rooms[room] = Room(room)
            elif choose == 3:
                role_name,room_name = input("请输入你要加入的角色和房间(请用空格隔开)：").split()
                rooms[room_name].add_member(roles[role_name])
            elif choose == 4:
                while True:
                    join = random.choice([0,1])
                    if join == 0:
                        rooms[room_name].member_list[0].attack(rooms[room_name].member_list[1])
                    else:
                        rooms[room_name].member_list[1].attack(rooms[room_name].member_list[0])
        else:
            print("输入错误！请输入数字1-5选择操作！")
    else:
        print("输入有误！请重新输入！")


